package com.codebattery.controller;

import com.codebattery.domain.entity.Order;
import com.codebattery.domain.model.MemeberOrderInfo;
import com.codebattery.domain.param.CartOrderInfo;
import com.codebattery.service.OrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/order")
public class OrderController {
    private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
    @Resource
    private OrderService orderService;

    @ApiOperation(value="从购物车创建订单",notes="订单")
    @RequestMapping(value="create-order-from-cart",method = RequestMethod.POST)
    @ResponseBody
//    @Idempotent(value = "/", expireMillis = 100000L)
    public Order createOrderFromCart(@RequestBody CartOrderInfo cartOrderInfo) throws Exception {
        Order order = orderService.createOrderFromCart(cartOrderInfo);

        return order;
    }

    @ApiOperation(value="获取所有订单",notes="订单")
    @RequestMapping(value="get-all-orders",method = RequestMethod.GET)
    public List<Order> getAllOrders() throws ExecutionException, InterruptedException {
//        CompletableFuture<List<Order>> allOrdersFuture = orderService.getAllOrders();
//        List<Order> orders = allOrdersFuture.get();
//
//        return orders;


        return null;

    }

    @ApiOperation(value="获取所有订单",notes="订单")
    @RequestMapping(value="get-member-orders",method = RequestMethod.GET)
    public PageInfo<MemeberOrderInfo> getMemberOrders(String memberId) throws ExecutionException, InterruptedException {

        PageInfo<MemeberOrderInfo> orders = orderService.getMemberOrders(memberId);

        return orders;
    }
}